﻿package model.drawPanel;

import java.util.ArrayList;

import model.drawPanel.entitys.Entity;

public class DrawOrder_Move extends DrawOrder {
	private int xmove,ymove,xchange,ychange;
	
	
	public DrawOrder_Move(int id,int xmove, int ymove) {
		super(id);
		this.xmove = xmove;
		this.ymove = ymove;
	}
	@Override
	public void execute(ArrayList<Entity> entitylist) {
		for(Entity en: entitylist){
			if(en.getId() == id){
				
				if(xchange!=0||ychange!=0){
				en.move(xchange, ychange);
				}else{
					en.move(xmove, ymove);
				}
			break;
			}
		}
		if(xchange!=0||ychange!=0){
			xchange =0;
			ychange =0;
			//移动过之后清零
		}
	}
	@Override
	public void undo(ArrayList<Entity> entitylist) {
		for(Entity en:entitylist){
			if(en.getId()==id){
				en.move(-xmove, -ymove);
				break;
			}
			
		}
	}
	@Override
	public void change(int x, int y) {
		xchange =x;
		ychange =y;
		xmove = xmove+x;
		ymove = ymove +y;
		
	}


}
